package com.example.myapplication2;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;

public class editText2Activity extends AppCompatActivity implements View.OnFocusChangeListener, View.OnClickListener {

    EditText user;
    EditText pass;
    Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_text2);
        user = findViewById(R.id.editUser);
        pass = findViewById(R.id.editPass);
        button = findViewById(R.id.editButton);
        //获得焦点事件
        user.setOnFocusChangeListener(this);
        pass.setOnFocusChangeListener(this);
        //设置点击监听
        button.setOnClickListener(this);
    }

    @Override
    public void onFocusChange(View view, boolean b) {
        switch (view.getId()){
            case R.id.editUser:
                if (b){
                    String s = user.getText().toString();
                    if (s!=null&&s.contains("Q")){
                        //将光标移动回去
                        user.requestFocus();
                        //提示消息
                        Toast.makeText(this,"输入有Q",Toast.LENGTH_SHORT).show();
                        System.out.println(s);
                    }
                }
                break;
            case R.id.editPass:
                if (b){

                }
                break;
        }
    }

    @Override
    public void onClick(View view) {

    }
}